<?php
namespace app\facescore\admin;
use app\admin\controller\Admin;
use app\facescore\model\FacescoreBanner as TypeModel;
use think\Db;

class Banner extends Admin
{
    public function index($q = '')
    {
        $map = [];
        if ($q) {
            $map['name'] = ['like', '%'.$q.'%'];
        }
        $data_list = Db::name('facescore_banner')->where($map)->order('shunxu desc')->paginate(10, false, ['query' => input('get.')]);;
        $pages = $data_list->render();
        $this->assign('data_list', $data_list);
        $this->assign('pages', $pages);
        return $this->fetch();
    }
    public function add()
    {
        if ($this->request->isPost()) {
            $mod = new TypeModel();
            if (!$mod->storage()) {
                return $this->error($mod->getError());
            }
            return $this->success('保存成功');
        }
        return $this->fetch('form');
    }
    public function edit()
    {
        $id = get_num();
        if ($this->request->isPost()) {
            $mod = new TypeModel();
            if (!$mod->storage()) {
                return $this->error($mod->getError());
            }
            return $this->success('保存成功');
        }
        $row = TypeModel::where('id', $id)->find();
        if (!$row) {
            return $this->error('数据不存在');
        }
        $this->assign('data_info', $row);
        return $this->fetch('form');
    }
}